package rabbitmq

import (
	"fmt"
	"github.com/streadway/amqp"
	"log"
	"os"
)

func getConnction() *amqp.Connection {
	// 获取环境变量中的 RabbitMQ 设置
	username := os.Getenv("RABBITMQ_USERNAME")
	password := os.Getenv("RABBITMQ_PASSWORD")
	host := os.Getenv("RABBITMQ_HOST")
	port := os.Getenv("RABBITMQ_PORT")
	// 建立连接到 RabbitMQ 服务器
	conn, err := amqp.Dial(fmt.Sprintf("amqp://%s:%s@%s:%s/", username, password, host, port))
	if err != nil {
		log.Fatalf("Failed to connect to RabbitMQ: %s", err)
	}
	return conn
}
